﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Web.Caching;
using YULI.Common;

namespace YULI.BLL
{
    public partial class sys_config
    {
        private readonly DAL.sys_config dal = new DAL.sys_config();

        /// <summary>
        ///  读取配置文件
        /// </summary>
        public Model.sys_config loadConfig()
        {
            Model.sys_config model = CacheHelper.Get<Model.sys_config>(YULIKeys.CACHE_SYS_CONFIG);
            if (model == null)
            {
                CacheHelper.Insert(YULIKeys.CACHE_SYS_CONFIG, dal.loadConfig(Utils.GetXmlMapPath(YULIKeys.FILE_SYS_XML_CONFING)),
                    Utils.GetXmlMapPath(YULIKeys.FILE_SYS_XML_CONFING));
                model = CacheHelper.Get<Model.sys_config>(YULIKeys.CACHE_SYS_CONFIG);
            }
            return model;
        }

        /// <summary>
        ///  读取配置文件
        /// </summary>
        public Model.sys_config loadConfigMemoryCache()
        {
            Model.sys_config result = MemoryCacheHelper.FindCacheItem<Model.sys_config>(YULIKeys.CACHE_SYS_CONFIG,
                () =>
                {
                    return dal.loadConfig(Utils.GetXmlMapPath(YULIKeys.FILE_SYS_XML_CONFING));
                }, new TimeSpan(0, 30, 0));


            return result;
        }

        /// <summary>
        ///  保存配置文件
        /// </summary>
        public Model.sys_config saveConifg(Model.sys_config model)
        {
            return dal.saveConifg(model, Utils.GetXmlMapPath(YULIKeys.FILE_SYS_XML_CONFING));
        }

    }
}
